#include "algdialog.h"
#include "ui_algdialog.h"

#include <QSettings>
#include <QTextCodec>
#include <QMessageBox>
AlgDialog::AlgDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::AlgDialog)
{
    ui->setupUi(this);
    m_nTag = 0;
}

AlgDialog::~AlgDialog()
{
    delete ui;
}

void AlgDialog::setPath(QString path, int n)
{

}

void AlgDialog::WdConfig()
{
    QString iniFilePath = "Config/config.ini";
    QSettings configIniWrite(iniFilePath, QSettings::IniFormat);
    configIniWrite.setIniCodec(QTextCodec::codecForName("UTF_8"));
    QString sInfo;
    QString sEdit;
    QLineEdit* m_edit;
    for(int i=0;i<7;i++){
        sEdit = QString("Edite_%1_C_%2").arg(i+1).arg(m_nTag+1);
        m_edit = this->findChild<QLineEdit*>(sEdit);
        sInfo = QString("AlgPart_%1/part%2").arg(m_nTag+1).arg(i+1);
        configIniWrite.setValue(sInfo, m_edit->text());
    }
    emit sigAlgToMain(3);
    QMessageBox::information(this, "info","success");
}

void AlgDialog::RdConfig()
{
    QString iniFilePath = "Config/config.ini";
    QSettings configIniRead(iniFilePath, QSettings::IniFormat);
    configIniRead.setIniCodec(QTextCodec::codecForName("UTF_8"));
    QString sInfo;
    QString sEdit;
    QLineEdit* m_edit;
    for(int tag = 0;tag<3;tag++){
        for(int i=0;i<7;i++){
            sEdit = QString("Edite_%1_C_%2").arg(i+1).arg(tag+1);
            m_edit = this->findChild<QLineEdit*>(sEdit);
            sInfo = QString("AlgPart_%1/part%2").arg(tag+1).arg(i+1);
            m_edit->setText(configIniRead.value(sInfo).toString());
        }
    }
}

void AlgDialog::ViewsInit()
{
    RdConfig();
}

void AlgDialog::on_Bt_write_C1_clicked()
{
    m_nTag = 0;
    WdConfig();

}

void AlgDialog::on_Bt_write_C_2_clicked()
{
    m_nTag = 1;
    WdConfig();
}

void AlgDialog::on_Bt_write_C_3_clicked()
{
    m_nTag = 2;
    WdConfig();
}
